<template>
  <div class="app-container yzh-basic">
    <avue-form
      v-if="formData.id"
      :option="formOption"
      v-model="formData"
      ref="formRef"
    >
      <!-- <template #cyhscb-label="{ column }">
        <span class="leading-snug">{{ column.label }}</span>
      </template> -->
      <!-- <template #menu-form="{ size }">
        <el-button
          icon="Search"
          type="primary"
          :size="size"
          @click="handleSubmit"
          >提交</el-button
        >
        <el-button icon="Refresh" :size="size" @click="handleReset(form)"
          >重置</el-button
        >
      </template> -->
    </avue-form>
  </div>
</template>
<script setup name="Basic">
import { reactive, toRefs, ref } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import useCommonStore from '@/store/modules/common'
import { listCategory } from '@/api/productMange/product'
const router = useRouter()
const route = useRoute()
const props = defineProps({
  productData: {
    type: Object,
    require: true
  }
})
const { proxy } = getCurrentInstance()
const commonStore = useCommonStore()
const sortOptions = ref([])
const companyData = ref([])
const {
  ord_product_plate_type,
  ord_product_plate,
  yes_or_no,
  measurement_unit,
  credit_rating,
  quantity_accuracy,
  addition_method,
  device_type,
  warehouse_info,
  self_product,
  product_bussiness_plate,
  transaction_type
} = proxy.useDict(
  'ord_product_plate_type',
  'ord_product_plate',
  'yes_or_no',
  'measurement_unit',
  'credit_rating',
  'quantity_accuracy',
  'addition_method',
  'device_type',
  'warehouse_info',
  'self_product',
  'product_bussiness_plate',
  'transaction_type'
)

commonStore.getCompanyData().then(e => {
  companyData.value = e
})
const data = reactive({
  formOption: {
    tabs: false,
    submitBtn: false,
    emptyBtn: false,
    disabled: true,
    labelWidth: '140',
    column: [
      {
        label: '名称',
        prop: 'name',
        span: 12,
        placeholder: '名称',
        type: 'input',
        rules: [
          {
            required: true,
            message: '请输入名称',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '编号',
        prop: 'number',
        span: 12,
        placeholder: '编号',
        type: 'input',
        rules: [
          {
            required: true,
            message: '请输入编号',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '分类',
        // labelWidth: '0',
        span: 12,
        prop: 'categoryId',
        placeholder: '分类',
        checkStrictly: true,
        type: 'tree',
        props: {
          value: 'id',
          label: 'name',
          children: 'children'
        },
        dicData: sortOptions,
        // focus: (column, value) => {
        //   column.column.dicData = sortOptions.value
        //   console.log('column', column)
        // },
        rules: [
          {
            required: true,
            message: '请选择分类',
            trigger: 'change'
          }
        ]
      },
      {
        label: '计量单位',
        // labelWidth: '0',
        span: 12,
        prop: 'unit',
        placeholder: '计量单位',
        type: 'select',
        dicData: measurement_unit,
        rules: [
          {
            required: true,
            message: '请选择计量单位',
            trigger: 'change'
          }
        ]
      },
      {
        label: '板块类型',
        // labelWidth: '0',
        span: 12,
        prop: 'plateType',
        placeholder: '板块类型',
        type: 'select',
        dicData: ord_product_plate_type
        // focus: () => {
        //   console.log(
        //     'ord_product_plate_type.value',
        //     ord_product_plate_type.value
        //   )
        // }
      },
      {
        label: '产业板块',
        // labelWidth: '0',
        span: 12,
        prop: 'industrialPlate',
        placeholder: '产业板块',
        type: 'select',
        dicData: ord_product_plate
      },
      {
        label: '规格型号',
        prop: 'specification',
        span: 12,
        placeholder: '规格型号',
        type: 'input',
        rules: [
          {
            required: false,
            message: '请输入规格型号',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '创建单位',
        // labelWidth: '0',
        span: 12,
        prop: 'createDept',
        placeholder: '创建单位',
        checkStrictly: true,
        type: 'tree',
        props: {
          value: 'id',
          label: 'label',
          children: 'children'
        },
        dicData: companyData
      },
      {
        label: 'MDM编码',
        prop: 'mdmNumber',
        span: 12,
        placeholder: 'MDM编码',
        type: 'input',
        rules: [
          {
            required: false,
            message: '请输入MDM编码',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '简称',
        prop: 'abbreviation',
        span: 12,
        placeholder: '简称',
        type: 'input',
        rules: [
          {
            required: false,
            message: '请输入简称',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '助记码',
        prop: 'mnemonic',
        span: 12,
        placeholder: '助记码',
        type: 'input'
      },
      {
        label: '配置',
        prop: 'configuration',
        span: 12,
        placeholder: '配置',
        type: 'input',
        rules: [
          {
            required: false,
            message: '请输入配置',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '外文名称',
        prop: 'foreignName',
        span: 12,
        placeholder: '外文名称',
        type: 'input',
        rules: [
          {
            required: false,
            message: '请输入外文名称',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '别名',
        prop: 'alias',
        span: 12,
        placeholder: '别名',
        type: 'input',
        rules: [
          {
            required: false,
            message: '请输入别名',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '注册商标',
        prop: 'trademark',
        span: 12,
        placeholder: '注册商标',
        type: 'input',
        rules: [
          {
            required: false,
            message: '请输入注册商标',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '税收分类',
        // labelWidth: '0',
        span: 12,
        prop: 'taxClassification',
        placeholder: '税收分类',
        type: 'input'
        // dicData: credit_rating
      },
      {
        label: '批准文号',
        prop: 'approvalNumber',
        span: 12,
        placeholder: '批准文号',
        type: 'input',
        rules: [
          {
            required: false,
            message: '请输入批准文号',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '税率',
        // labelWidth: '0',
        span: 12,
        prop: 'taxRate',
        placeholder: '税收税率',
        type: 'input'
        // dicData: credit_rating.value
      },
      {
        label: '享受税收优惠政策',
        prop: 'enjoyPreferential',
        type: 'radio',
        dicData: yes_or_no
      },
      {
        label: '优惠政策类型',
        // labelWidth: '0',
        span: 12,
        prop: 'preferentialType',
        placeholder: '优惠政策类型',
        type: 'input'
        // dicData: credit_rating
      },
      {
        label: '数量精度',
        // labelWidth: '0',
        span: 12,
        prop: 'accuracy',
        placeholder: '数量精度',
        type: 'select',
        dicData: quantity_accuracy
      },
      {
        label: '劳务服务',
        prop: 'laborService',
        type: 'radio',
        dicData: yes_or_no
      },
      {
        label: '是否新物料',
        prop: 'isNew',
        type: 'radio',
        dicData: yes_or_no
      },
      {
        label: ' 新物料有效年月',
        // labelWidth: '0',
        span: 12,
        prop: 'effectiveDate',
        type: 'date',
        placeholder: '新物料有效年月',
        format: 'YYYY-MM-DD',
        valueFormat: 'YYYY-MM-DD'
      },
      {
        label: '设备类型',
        prop: 'deviceType',
        type: 'radio',
        dicData: device_type
      },
      {
        label: '自研物料',
        // labelWidth: '0',
        span: 12,
        prop: 'selfProduct',
        placeholder: '自研物料',
        type: 'select',
        dicData: self_product
      },
      {
        label: '总部管理',
        prop: 'headManage',
        type: 'radio',
        dicData: yes_or_no
      },
      {
        label: '是否硬件',
        prop: 'isHardware',
        type: 'radio',
        dicData: yes_or_no
      },
      {
        label: '物料业务板块',
        // labelWidth: '0',
        span: 12,
        prop: 'productBussinessPlate',
        placeholder: '物料业务板块',
        type: 'select',
        dicData: product_bussiness_plate
      },
      {
        label: '往来业务板块',
        prop: 'transactionPlate',
        span: 12,
        placeholder: '往来业务板块',
        type: 'input',
        rules: [
          {
            required: false,
            message: '请输入往来业务板块',
            trigger: 'blur'
          }
        ]
      }

      /* {
            label: '上传合同',
            prop: 'imgUrl',
            type: 'upload',
            span: 12,
            fileText: '上传合同',
            propsHttp: {
              url: 'url',
              name: 'name',
              res: 'data'
            },
            action: action
          }, */
    ]
  },
  formData: {}
})
let { formOption, formData } = toRefs(data)

watchEffect(() => {
  if (props.productData) {
    formData.value = props.productData
  }
})

/** 获取分类下拉树结构 */
function getTreeselect() {
  sortOptions.value = []
  let tree = {
    id: 0,
    name: '根目录',
    children: []
  }
  listCategory().then(res => {
    tree.children = res.data //proxy.handleTree(res.data)
    sortOptions.value.push(tree)
    // formOption.value.group[1].column[2].dicData = sortOptions.value
  })
}
getTreeselect()
</script>
<style lang="scss" scoped></style>
